package com.wang.weblog.admin.controller;

import com.wang.weblog.admin.model.vo.user.UpdateAdminUserPasswordReqVO;
import com.wang.weblog.admin.service.AdminUserService;
import com.wang.weblog.common.aspect.ApiOperationLog;
import com.wang.weblog.common.utils.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Slf4j
@RequestMapping("/admin")
@Api(tags = "Admin 用户模块")
public class AdminUserController {

    @Resource
    private AdminUserService adminUserService;

    @PostMapping("/password/update")
    @ApiOperation("修改用户密码")
    @ApiOperationLog(description = "修改用户密码")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response updatePassword(@Validated @RequestBody UpdateAdminUserPasswordReqVO updateAdminUserPasswordReqVO){
        return adminUserService.updatePassword(updateAdminUserPasswordReqVO);
    }

    @PostMapping("/user/info")
    @ApiOperation(value = "获取用户信息")
    @ApiOperationLog(description = "获取用户信息")
    public Response findUserInfo(){
        return adminUserService.findUserInfo();
    }
}
